Skip to content

Improve REST API routing and test architecture#15

Closed
cgwalters wants to merge 2 commits into
mainfrom
agent-improve-rest-api-routing
Closed

Improve REST API routing and test architecture#15
cgwalters wants to merge 2 commits into
mainfrom
agent-improve-rest-api-routing

Conversation

@cgwalters

Copy link
Copy Markdown
Collaborator

Summary

This PR addresses the issues identified in PR #14 by improving the REST API implementation:

🔧 Service-Specific API Routing

  • Fixed heuristic routing: Previously the router used hard-coded patterns to strip /api/v3, /api/v2 etc., which was not service-specific
  • Service-aware routing: Now each service (GitHub, GitLab, Forgejo, JIRA) handles its own API prefix correctly
  • Better maintainability: The get_service() method now returns both the service and its specific prefix, eliminating the need for generic prefix stripping

📊 Table-Driven Tests

  • Reduced verbosity: Converted repetitive REST API integration tests to use data-driven patterns
  • Better maintainability: Test cases are now defined as data structures, making it easier to add new test scenarios
  • Eliminated duplication: Consolidated similar test functions into parameterized test runners

⚡ Async HTTP Improvements

  • Proper async patterns: Ensured HTTP handlers use async/await correctly throughout
  • Better error handling: Improved error propagation in async contexts

Technical Details

The key changes:

  1. src/services/mod.rs: Modified get_service() to return (service, prefix) tuple instead of just the service
  2. src/servers/rest.rs: Updated to use service-specific prefix stripping instead of heuristic approach
  3. integration-tests/src/tests/rest_api.rs: Converted verbose test functions to table-driven patterns

This makes the codebase more maintainable and fixes the "fishy" routing logic that was mentioned in the original issue.

It's really convenient and understandable for agents if they can run the
`gh` CLI directly. We can enable this by setting proxy variables.

Implement this for gitlab and forgejo as well.

Assisted-by: OpenCode (Claude 3.5 Sonnet)
Signed-off-by: Colin Walters <walters@verbum.org>
- Fix API routing to be service-specific instead of heuristic
  * get_service() now returns both service and service-specific prefix
  * Eliminates hard-coded API version stripping in favor of service-aware routing
  * Each service (GitHub /api/v3, GitLab /api/v4, etc.) handles its own prefix

- Convert verbose REST API tests to table-driven patterns
  * Reduce code duplication in integration tests
  * Use data structures to define test cases
  * More maintainable and easier to extend

Assisted-by: OpenCode (Sonnet 4.5)
@cgwalters cgwalters closed this Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant